package com.njcs.Inconsistentsynchronization;

/**
 * @author Sam.Lee E-mail:lishanman2007@163.com
 * @version Created：Jul 28, 2011 9:13:51 AM
 */
public class Test extends Thread {
	public static void main(String args[]) throws InterruptedException {
		ObjectClass obj = new ObjectClass();

		Thread t2 = new ChangeValue(obj);
		t2.start();

		Thread t1 = new AlwaysRun(obj);
		t1.start();

		sleep(10000);
		t1.stop();
	}
}

class ChangeValue extends Thread {

	ObjectClass obj;

	ChangeValue(ObjectClass obj) {
		this.obj = obj;
	}

	public void run() {

		System.out.println("Thread2");
		ObjClass2 obj2 = obj.getObj();

		try {
			sleep(1500);
		} catch (InterruptedException e) {
			System.out.println("Error!");
		}

		obj2.str = "aaa";
		System.out.println("Thread2 Finish!");
	}
}

class AlwaysRun extends Thread {

	ObjectClass obj;

	public AlwaysRun(ObjectClass obj) {
		this.obj = obj;
	}

	public void run() {
		obj.Loop();
	}
}